﻿using System;
using System.Data;
using System.Collections.Generic;

namespace SIS.DataAccess
{
	/// <summary>
	/// Author: hieunv
	/// </summary>
	class Summaries : DataTable
	{
		public const string SEMESTER = "semester";
		public const string YEAR = "year";
		public const string TOTAL_CREDITS = "TotalCredits";
		public const string GPA = "GPA";
		public const string CPA = "CPA";
		public const string RATING = "Rating";
		public const string XTH_YEAR = "xthYear";
		public Summaries()
			: base("Summaries")
		{
			var semester = new DataColumn(SEMESTER, typeof(string));
			semester.AllowDBNull = false;
			this.Columns.Add(semester);
			var year = new DataColumn(YEAR, typeof(int));
			year.AllowDBNull = false;
			this.Columns.Add(year);
			var totalCredits = new DataColumn(TOTAL_CREDITS, typeof(string));
			totalCredits.AllowDBNull = false;
			this.Columns.Add(totalCredits);
			var gpa = new DataColumn(GPA, typeof(float));
			gpa.AllowDBNull = false;
			this.Columns.Add(gpa);
			var cpa = new DataColumn(CPA, typeof(float));
			cpa.AllowDBNull = false;
			this.Columns.Add(cpa);
			var rating = new DataColumn(RATING, typeof(string));
			rating.AllowDBNull = false;
			this.Columns.Add(rating);
			var xthYear = new DataColumn(XTH_YEAR, typeof(int));
			xthYear.AllowDBNull = false;
			this.Columns.Add(xthYear);

			this.PrimaryKey = new DataColumn[] { semester, year };
		}

		public void Fill(string studentID)
		{
			this.Clear();
			List<System.Data.SqlClient.SqlParameter> parameters = new List<System.Data.SqlClient.SqlParameter>();
			System.Data.SqlClient.SqlParameter p1 = new System.Data.SqlClient.SqlParameter("@studentID", SqlDbType.VarChar, 5, "");
			p1.Value = studentID;
			parameters.Add(p1);
			DataServices.ExecuteQuery(QueryType.SELECT, CommandType.StoredProcedure, "sp_Summaries", parameters, this);
		}
	}
}
